home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / sql-bench / innotest1b < prev    next >
Encoding:
Text File  |  2003-01-22  |  3.5 KB  |  101 lines  |  [TEXT/ttxt]

  1. #!/usr/bin/perl
  2. ############################################################################
  3. #     Stress test for MySQL/InnoDB combined database
  4. #     (c) 2002 Innobase Oy & MySQL AB
  5. #
  6. ############################################################################
  7.  
  8. use DBI;
  9. use Benchmark;
  10.  
  11. $opt_loop_count = 200000;
  12.  
  13. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  14. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  15.  
  16. print "Innotest1b: MySQL/InnoDB stress test in Perl\n";
  17. print "-------------------------------------------\n";
  18. print "This is a randomized stress test for concurrent inserts,\n";
  19. print "updates, deletes, commits and rollbacks. The test will generate\n";
  20. print "also a lot of deadlocks, duplicate key errors, and other SQL errors.\n";
  21. print "\n";
  22. print "You should run innotest1, innotest1a, and innotest1b concurrently.\n";
  23. print "The thing to watch is that the server does not crash or does not\n";
  24. print "print to the .err log anything. Currently, due to a buglet in MySQL,\n";
  25. print "warnings about MySQL lock reservations can appear in the .err log.\n";
  26. print "The test will run very long, even several hours. You can kill\n";
  27. print "the perl processes running this test at any time and do CHECK\n";
  28. print "TABLE on table innotest1 in the 'test' database.\n";
  29. print "\n";
  30. print "Some of these stress tests will print a lot of SQL errors\n";
  31. print "to the standard output. That is not to be worried about.\n";
  32. print "You can direct the output to a file like this:\n";
  33. print "perl innotest1 > out1\n\n";
  34.  
  35. print "Generating random keys\n";
  36. $random[$opt_loop_count] = 0;
  37. $rnd_str[$opt_loop_count] = "a";
  38.  
  39. for ($i = 0; $i < $opt_loop_count; $i++) {
  40.  
  41.     $random[$i] = ($i * 63857) % $opt_loop_count;
  42.  
  43.       if (0 == ($random[$i] % 3)) {
  44.           $rnd_str[$i] = "kjgclgrtfuylfluyfyufyulfulfyyulofuyolfyufyufuyfyufyufyufyufyyufujhfghd";
  45.     } else { if (1 == ($random[$i] % 3)) {
  46.         $rnd_str[$i] = "khd";
  47.     } else { if (2 == ($random[$i] % 3)) {
  48.         $rnd_str[$i] = "kh";
  49.     }}}
  50.  
  51.     for ($j = 0; $j < (($i * 764877) % 20); $j++) {
  52.         $rnd_str[$i] = $rnd_str[$i]."k";
  53.     }    
  54. }
  55.  
  56. ####
  57. ####  Connect
  58. ####
  59.  
  60. $dbh = $server->connect()
  61. || die $dbh->errstr;
  62.  
  63. $dbh->do("set autocommit = 0");
  64.  
  65. for ($i = 0; $i < 5; $i++) {
  66.     print "loop $i\n";
  67.  
  68.     for ($j = 1; $j < $opt_loop_count - 10; $j = $j + 2) {
  69.  
  70.         fetch_all_rows($dbh, "select b, c from innotest1 where a > ".$random[$j]." and a < ".($random[$j] + 7));
  71.         
  72.         if (0 == ($j % 37)) {
  73.             $dbh->do("commit");
  74.         }
  75.  
  76.         if (0 == ($j % 533)) {
  77.             $dbh->do("rollback");
  78.         }        
  79.  
  80.         if (0 == ($j % 537)) {
  81.         print fetch_all_rows($dbh, "select c from innotest1 where c = '".$rnd_str[$j - 67]."'");
  82.         print fetch_all_rows($dbh, "select b from innotest1 where b = '".$rnd_str[$j - 688]."'");
  83.         print fetch_all_rows($dbh, "select b, c from innotest1 where c = '".$rnd_str[$j - 67]."'");
  84.         print fetch_all_rows($dbh, "select b, c from innotest1 where b = '".$rnd_str[$j - 622]."'");
  85.         print fetch_all_rows($dbh, "select a, b, c from innotest1 where c = '".$rnd_str[$j - 68]."'");
  86.         print fetch_all_rows($dbh, "select a, b, c from innotest1 where b = '".$rnd_str[$j - 644]."'");
  87.         print fetch_all_rows($dbh, "select d, b, c from innotest1 where c = '".$rnd_str[$j - 68]."'");
  88.         print fetch_all_rows($dbh, "select d, b, c from innotest1 where b = '".$rnd_str[$j - 677]."'");
  89.         print "\n";
  90.         }
  91.  
  92.         if (0 == (($j - 1) % 1000)) {
  93.             print "round $j\n";
  94.         }
  95.     }    
  96.     
  97.     $dbh->do("commit");
  98. }                
  99.  
  100. $dbh->disconnect;                # close connection
  101.